<?php
global $dktmSetting;
show_admin_bar(false);
add_filter('widget_text', 'do_shortcode');
define('DKTM_SECURITY_KEY', 'dktm@123');
define('DKTM_OPTION_KEY', 'dktmSettings');
add_action('init', 'my_add_excerpts_to_pages');

function my_add_excerpts_to_pages() {
    add_post_type_support('page', 'excerpt');
}

function debug($msg) {
    echo '<pre>';
    print_r($msg);
    echo '</pre>';
}

if (!is_admin()) {
    $dktmSetting = unserialize(get_option(DKTM_OPTION_KEY));
}

if (!isset($content_width))
    $content_width = 640; /* pixels */

if (!function_exists('ec_setup')):

    function ec_setup() {
        load_theme_textdomain('ec', get_template_directory() . '/languages');
        $locale = get_locale();
        $locale_file = get_template_directory() . "/languages/$locale.php";
        if (is_readable($locale_file))
            require_once( $locale_file );
        /**
         * Add default posts and comments RSS feed links to head
         */
        add_theme_support('automatic-feed-links');
        add_theme_support('custom-header');
        add_theme_support('custom-background');

        /**
         * This theme uses wp_nav_menu() in one location.
         */
        register_nav_menus(array(
            'main-menu' => __('Main Header Menu', 'ec'),
        ));
        register_nav_menus(array(
            'side-menu' => __('Side Menu', 'ec'),
        ));
        register_nav_menus(array(
            'footer-menu' => __('Footer Menu', 'ec'),
        ));

        /**
         * Add support for the Aside and Gallery Post Formats
         */
        add_theme_support('post-formats', array('aside', 'image', 'gallery'));
    }

endif; // ec_setup

/**
 * Tell WordPress to run ec_setup() when the 'after_setup_theme' hook is run.
 */
add_action('after_setup_theme', 'ec_setup');

/**
 * Set a default theme color array for WP.com.
 */
$themecolors = array(
    'bg' => 'ffffff',
    'border' => 'eeeeee',
    'text' => '444444',
);

/**
 * Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
 */
function ec_page_menu_args($args) {
    $args['show_home'] = true;
    return $args;
}

add_filter('wp_page_menu_args', 'ec_page_menu_args');

/**
 * Register widgetized area and update sidebar with default widgets
 */
function ec_widgets_init() {
    register_sidebar(array(
        'name' => "Home Boxes",
        'id' => 'home-box',
        'before_widget' => '<aside>',
        'after_widget' => '</aside>',
        'before_title' => '<h3>',
        'after_title' => '</h3>'
    ));
    register_sidebar(array(
        'name' => "Blog Widget",
        'id' => 'blog-widget',
        'description' => __('blog widget area', 'ec'),
        'before_widget' => '<aside class="span3"><div class="sidepanel %2$s">',
        'after_widget' => '</div></aside>',
        'before_title' => '<div class="bg_title"><h4 class="sidebar_header">',
        'after_title' => '</h4></div>'
    ));
    register_sidebar(array(
        'name' => "Entertainment Widget",
        'id' => 'entertainment-widget',
        'description' => __('entertainment widget area', 'ec'),
        'before_widget' => '<aside class="span3 entertainment"><div class="sidepanel %2$s">',
        'after_widget' => '</div></aside>',
        'before_title' => '<div class="bg_title"><h4 class="sidebar_header">',
        'after_title' => '</h4></div>'
    ));

    register_sidebar(array(
        'name' => "Footer Widget",
        'id' => 'page-sidebar-2',
        'description' => __('footer widget area', 'ec'),
        'before_widget' => '<aside class="span3"><div class="sidepanel %2$s">',
        'after_widget' => '</div></aside>',
        'before_title' => '<div class="bg_title"><h4 class="sidebar_header">',
        'after_title' => '</h4></div>'
    ));
    register_sidebar(array(
        'name' => __('Information Widget', 'ec'),
        'id' => 'information-widget',
        'description' => __('information widget area', 'ec'),
        'before_widget' => '<aside id="%1$s" class="widget %2$s">',
        'after_widget' => "</aside><div class='clear'></div>",
        'before_title' => '<h1 class="widget-title">',
        'after_title' => '</h1>',
    ));
    register_sidebar(array(
        'name' => __('Event Widget', 'ec'),
        'id' => 'event-widget',
        'description' => __('event widget area', 'ec'),
        'before_widget' => '<aside id="%1$s" class="widget %2$s">',
        'after_widget' => "</aside>",
        'before_title' => '<h1 class="widget-title">',
        'after_title' => '</h1>',
    ));
}

add_action('init', 'ec_widgets_init');

if (!function_exists('ec_content_nav')):

    /**
     * Display navigation to next/previous pages when applicable
     *
     */
    function ec_content_nav($nav_id) {
        global $wp_query;
        ?>
        <nav id="<?php echo $nav_id; ?>">
            <h1 class="assistive-text section-heading"><?php _e('Post navigation', 'ec'); ?></h1>

            <?php if (is_single()) : // navigation links for single posts     ?>

                <?php previous_post_link('<div class="nav-previous">%link</div>', '<span class="meta-nav">' . _x('&larr;', 'Previous post link', 'ec') . '</span> %title'); ?>
                <?php next_post_link('<div class="nav-next">%link</div>', '%title <span class="meta-nav">' . _x('&rarr;', 'Next post link', 'ec') . '</span>'); ?>

            <?php elseif ($wp_query->max_num_pages > 1 && ( is_home() || is_archive() || is_search() )) : // navigation links for home, archive, and search pages      ?>

                <?php if (get_next_posts_link()) : ?>
                    <div class="nav-previous"><?php next_posts_link(__('<span class="meta-nav">&larr;</span> Older posts', 'ec')); ?></div>
                <?php endif; ?>

                <?php if (get_previous_posts_link()) : ?>
                    <div class="nav-next"><?php previous_posts_link(__('Newer posts <span class="meta-nav">&rarr;</span>', 'ec')); ?></div>
                <?php endif; ?>

            <?php endif; ?>

        </nav><!-- #<?php echo $nav_id; ?> -->
        <?php
    }

endif; // ec_content_nav


if (!function_exists('ec_comment')) :

    /**
     * Template for comments and pingbacks.
     *
     * To override this walker in a child theme without modifying the comments template
     * simply create your own ec_comment(), and that function will be used instead.
     *
     * Used as a callback by wp_list_comments() for displaying the comments.
     *
     */
    function ec_comment($comment, $args, $depth) {
        $GLOBALS['comment'] = $comment;
        switch ($comment->comment_type) :
            case 'pingback' :
            case 'trackback' :
                ?>
                <li class="post pingback">
                    <p><?php _e('Pingback:', 'ec'); ?> <?php comment_author_link(); ?><?php edit_comment_link(__('(Edit)', 'ec'), ' '); ?></p>
                    <?php
                    break;
                default :
                    ?>
                <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
                    <article id="comment-<?php comment_ID(); ?>" class="comment">
                        <footer>
                            <div class="comment-author vcard">
                                <?php echo get_avatar($comment, 40); ?>
                                <?php printf(__('%s <span class="says">says:</span>', 'ec'), sprintf('<cite class="fn">%s</cite>', get_comment_author_link())); ?>
                            </div><!-- .comment-author .vcard -->
                            <?php if ($comment->comment_approved == '0') : ?>
                                <em><?php _e('Your comment is awaiting moderation.', 'ec'); ?></em>
                                <br />
                            <?php endif; ?>

                            <div class="comment-meta commentmetadata">
                                <a href="<?php echo esc_url(get_comment_link($comment->comment_ID)); ?>"><time pubdate datetime="<?php comment_time('c'); ?>">
                                        <?php
                                        /* translators: 1: date, 2: time */
                                        printf(__('%1$s at %2$s', 'ec'), get_comment_date(), get_comment_time());
                                        ?>
                                    </time></a>
                                <?php edit_comment_link(__('(Edit)', 'ec'), ' ');
                                ?>
                            </div><!-- .comment-meta .commentmetadata -->
                        </footer>

                        <div class="comment-content"><?php comment_text(); ?></div>

                        <div class="reply">
                            <?php comment_reply_link(array_merge($args, array('depth' => $depth, 'max_depth' => $args['max_depth']))); ?>
                        </div><!-- .reply -->
                    </article><!-- #comment-## -->

                    <?php
                    break;
            endswitch;
        }

    endif; // ends check for ec_comment()

    if (!function_exists('ec_posted_on')) :

        /**
         * Prints HTML with meta information for the current post-date/time and author.
         * Create your own ec_posted_on to override in a child theme
         *
         */
        function ec_posted_on() {
            printf(__('<span class="sep">Posted on </span><a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s" pubdate>%4$s</time></a><span class="byline"> <span class="sep"> by </span> <span class="author vcard"><a class="url fn n" href="%5$s" title="%6$s" rel="author">%7$s</a></span></span>', 'ec'), esc_url(get_permalink()), esc_attr(get_the_time()), esc_attr(get_the_date('c')), esc_html(get_the_date()), esc_url(get_author_posts_url(get_the_author_meta('ID'))), esc_attr(sprintf(__('View all posts by %s', 'ec'), get_the_author())), esc_html(get_the_author())
            );
        }

    endif;

    /**
     * Adds custom classes to the array of body classes.
     */
    function ec_body_classes($classes) {
        // Adds a class of single-author to blogs with only 1 published author
        if (!is_multi_author()) {
            $classes[] = 'single-author';
        }

        return $classes;
    }

    add_filter('body_class', 'ec_body_classes');

    /**
     * Returns true if a blog has more than 1 category
     */
    function ec_categorized_blog() {
        if (false === ( $all_the_cool_cats = get_transient('all_the_cool_cats') )) {
            // Create an array of all the categories that are attached to posts
            $all_the_cool_cats = get_categories(array(
                'hide_empty' => 1,
            ));

            // Count the number of categories that are attached to the posts
            $all_the_cool_cats = count($all_the_cool_cats);

            set_transient('all_the_cool_cats', $all_the_cool_cats);
        }

        if ('1' != $all_the_cool_cats) {
            // This blog has more than 1 category so ec_categorized_blog should return true
            return true;
        } else {
            // This blog has only 1 category so ec_categorized_blog should return false
            return false;
        }
    }

    /**
     * Flush out the transients used in ec_categorized_blog
     */
    function ec_category_transient_flusher() {
        // Like, beat it. Dig?
        delete_transient('all_the_cool_cats');
    }

    add_action('edit_category', 'ec_category_transient_flusher');
    add_action('save_post', 'ec_category_transient_flusher');

    /**
     * Filter in a link to a content ID attribute for the next/previous image links on image attachment pages
     */
    function ec_enhanced_image_navigation($url) {
        global $post, $wp_rewrite;
        $id = (int) $post->ID;
        $object = get_post($id);
        if (wp_attachment_is_image($post->ID) && ( $wp_rewrite->using_permalinks() && ( $object->post_parent > 0 ) && ( $object->post_parent != $id ) ))
            $url = $url . '#main';

        return $url;
    }

    add_filter('attachment_link', 'ec_enhanced_image_navigation');
    add_theme_support('post-thumbnails');
    add_editor_style('css/custom-editor-style.css');

    /**
     * This theme was built with PHP, Semantic HTML, CSS, love, and a ec.
     */
    /* Added by subin */
    add_action('init', 'rs3_custom_post_information');
    add_action('add_meta_boxes', 'rs3_detail_box');
    add_action('save_post', 'rs3_detail_box_save');

    add_action('add_meta_boxes', 'rs3_external_url_box');
    add_action('save_post', 'rs3_external_url_box_save');
    add_image_size('thumb-med', 900, 600, true);
    add_image_size('thumb-small', 100, 100, true);
    add_image_size('thumbnail-220x148', 220, 148, true);
    add_image_size('thumbnail-560x309', 560, 309, true);
    add_image_size('thumbnail-280x175', 280, 175, true);



    if (!function_exists('rs3_custom_post_information')) {

        function rs3_custom_post_information() {
            $labelInformations = array(
                'name' => _x('Informations', 'post type general name'),
                'singular_name' => _x('Information', 'post type singular name'),
                'add_new' => _x('Add New', 'dktm'),
                'add_new_item' => __('Add New Information'),
                'edit_item' => __('Edit Information'),
                'new_item' => __('New Information'),
                'all_items' => __('All Informations'),
                'view_item' => __('View Information'),
                'search_items' => __('Search Informations'),
                'not_found' => __('No informations found'),
                'not_found_in_trash' => __('No informations found in the Trash'),
                'parent_item_colon' => '',
                'menu_name' => 'Informations'
            );
            $argInformations = array(
                'labels' => $labelInformations,
                'description' => 'Holds dktm informations and information specific data',
                'public' => true,
                'menu_position' => 20,
                'supports' => array('title', 'editor', 'thumbnail', 'excerpt', 'comments'), //, 'custom-fields'
                'has_archive' => true,
                'taxonomies' => array()
            );
            register_post_type('information', $argInformations);
        }

    }
    if (!function_exists('rs3_detail_box')) {

        function rs3_detail_box() {
            add_meta_box('information_detail_box', __('Information Detail'), 'information_detail_box_content', 'information', 'side', 'default');
        }

    }

    if (!function_exists('information_detail_box_content')) {

        function information_detail_box_content($object, $box) {
            wp_nonce_field(plugin_basename(__FILE__), 'information_detail_box_content_nonce');
            $checked = (get_post_meta($object->ID, 'latest_news_activate', true) == 1) ? 'checked="checked"' : '';
            ?>
            <p>
                <label for="activate-latest-news"><?php _e("Activate as latest News:", 'information'); ?></label>
                <input type="checkbox" <?php echo $checked; ?> name="latest_news_activate" id="activate-latest-news" value="1" />
            </p>
            <p>
                <label for="latest-news-message"><?php _e("Latest News Message:", 'information'); ?></label>
                <textarea class="widefat" name="latest_news_message" id="latest-news-message"><?php echo esc_attr(get_post_meta($object->ID, 'latest_news_message', true)); ?></textarea>
            </p>
            <?php
        }

    }


    if (!function_exists('rs3_detail_box_save')) {

        function rs3_detail_box_save($post_id) {
            if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
                return;
            if (!wp_verify_nonce(@$_POST['information_detail_box_content_nonce'], plugin_basename(__FILE__)))
                return;
            if ('page' == $_POST['post_type']) {
                if (!current_user_can('edit_page', $post_id))
                    return;
            } else {
                if (!current_user_can('edit_post', $post_id))
                    return;
            }
            $latest_news_activate = (@$_POST['latest_news_activate'] == "1") ? 1 : 0;
            $latest_news_message = @$_POST['latest_news_message'];
            update_post_meta($post_id, 'latest_news_activate', $latest_news_activate);
            update_post_meta($post_id, 'latest_news_message', $latest_news_message);
        }

    }

    if (!function_exists('rs3_external_url_box')) {

        function rs3_external_url_box($postType) { //to add for multiple post type
            $types = array('information', 'post', 'tribe_events');
            if (in_array($postType, $types)) {
                add_meta_box('external_url_box', __('External Featured Image'), 'external_url_box_content', $postType, 'side', 'default');
            }
        }

    }

    if (!function_exists('external_url_box_content')) {

        function external_url_box_content($object, $box) {
            wp_nonce_field(plugin_basename(__FILE__), 'external_url_box_content_nonce');
            ?>
            <p>
                <label for="external_url"><?php _e("External Url:", 'information'); ?></label>
                <textarea class="widefat" name="external_url" id="external_url"><?php echo esc_attr(get_post_meta($object->ID, 'external_url', true)); ?></textarea>
            </p>
            <?php
        }

    }
    if (!function_exists('rs3_external_url_box_save')) {

        function rs3_external_url_box_save($post_id) {
            if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
                return;
            if (!wp_verify_nonce(@$_POST['external_url_box_content_nonce'], plugin_basename(__FILE__)))
                return;
            if ('page' == $_POST['post_type']) {
                if (!current_user_can('edit_page', $post_id))
                    return;
            } else {
                if (!current_user_can('edit_post', $post_id))
                    return;
            }
            $external_url = @$_POST['external_url'];
            update_post_meta($post_id, 'external_url', $external_url);
        }

    }


    add_action('admin_menu', 'rs3_add_pages');

    function rs3_add_pages() { //main admin setting page
        $setting_page = add_menu_page(__('DKTM Settings', 'dktm'), __('DKTM Settings', 'dktm'), 'manage_options', 'dktm-settings', 'dktm_setting');
        $setting_page = add_submenu_page('dktm-settings', __('DKTM Setting', 'dktm'), __('DKTM Setting', 'dktm'), 'manage_options', 'dktm-settings', 'dktm_setting');
        //add_action("admin_print_scripts-$setting_page", 'enqueue_jq');
    }

    function dktm_setting() {
        include_once( TEMPLATEPATH . '/helpers/admin_dktm_setting.php' );
    }

    function dktm_breadcrumbs() { //ref: http://dimox.net/wordpress-breadcrumbs-without-a-plugin/
        $delimiter = '&raquo;';
        $home = 'Home'; // text for the 'Home' link
        $before = '<span class="current">'; // tag before the current crumb
        $after = '</span>'; // tag after the current crumb

        if (!is_home() && !is_front_page() || is_paged()) {
            echo '<div id="crumbs">';
            global $post;
            $homeLink = home_url(); // get_bloginfo('url');
            echo '<a href="' . $homeLink . '">' . $home . '</a> ' . $delimiter . ' ';
            if (is_category()) {
                global $wp_query;
                $cat_obj = $wp_query->get_queried_object();
                $thisCat = $cat_obj->term_id;
                $thisCat = get_category($thisCat);
                $parentCat = get_category($thisCat->parent);
                if ($thisCat->parent != 0)
                    echo(get_category_parents($parentCat, TRUE, ' ' . $delimiter . ' '));
                echo $before . 'Archive by category "' . single_cat_title('', false) . '"' . $after;
            } elseif (is_day()) {
                echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
                echo '<a href="' . get_month_link(get_the_time('Y'), get_the_time('m')) . '">' . get_the_time('F') . '</a> ' . $delimiter . ' ';
                echo $before . get_the_time('d') . $after;
            } elseif (is_month()) {
                echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
                echo $before . get_the_time('F') . $after;
            } elseif (is_year()) {
                echo $before . get_the_time('Y') . $after;
            } elseif (is_single() && !is_attachment()) {
                if (get_post_type() != 'post') {
                    $post_type = get_post_type_object(get_post_type());
                    $slug = $post_type->rewrite;
                    echo '<a href="' . $homeLink . '/' . $slug['slug'] . '/">' . $post_type->labels->singular_name . '</a> ' . $delimiter . ' ';
                    echo $before . get_the_title() . $after;
                } else {
                    $cat = get_the_category();
                    $cat = $cat[0];
                    echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
                    echo $before . get_the_title() . $after;
                }
            } elseif (!is_single() && !is_page() && get_post_type() != 'post') {
                $post_type = get_post_type_object(get_post_type());
                echo $before . $post_type->labels->singular_name . $after;
            } elseif (is_attachment()) {
                $parent = get_post($post->post_parent);
                $cat = get_the_category($parent->ID);
                $cat = $cat[0];
                echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
                echo '<a href="' . get_permalink($parent) . '">' . $parent->post_title . '</a> ' . $delimiter . ' ';
                echo $before . get_the_title() . $after;
            } elseif (is_page() && !$post->post_parent) {
                echo $before . get_the_title() . $after;
            } elseif (is_page() && $post->post_parent) {
                $parent_id = $post->post_parent;
                $breadcrumbs = array();
                while ($parent_id) {
                    $page = get_page($parent_id);
                    $breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>';
                    $parent_id = $page->post_parent;
                }
                $breadcrumbs = array_reverse($breadcrumbs);
                foreach ($breadcrumbs as $crumb)
                    echo $crumb . ' ' . $delimiter . ' ';
                echo $before . get_the_title() . $after;
            } elseif (is_search()) {
                echo $before . 'Search results for "' . get_search_query() . '"' . $after;
            } elseif (is_tag()) {
                echo $before . 'Posts tagged "' . single_tag_title('', false) . '"' . $after;
            } elseif (is_author()) {
                global $author;
                $userdata = get_userdata($author);
                echo $before . 'Articles posted by ' . $userdata->display_name . $after;
            } elseif (is_404()) {
                echo $before . 'Error 404' . $after;
            }
            if (get_query_var('paged')) {
                if (is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author())
                    echo ' (';
                echo __('Page') . ' ' . get_query_var('paged');
                if (is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author())
                    echo ')';
            }
            echo '</div>';
        }
    }

    function dktm_main_nav() {
        // display the wp3 menu if available
        wp_nav_menu(array(
            'container' => false, // remove nav container
            'container_class' => 'menu clearfix', // class of container (should you choose to use it)
            'menu' => __('Main Menu', 'dktm'), // nav name
            'menu_class' => 'nav top-nav', // adding custom nav class
            'theme_location' => 'main-menu', // where it's located in the theme
            'before' => '', // before the menu
            'after' => '', // after the menu
            'link_before' => '', // before each link
            'link_after' => '', // after each link
            'depth' => 0, // limit the depth of the nav
            'fallback_cb' => 'dktm_main_nav_fallback'      // fallback function
        ));
    }

    function dktm_main_nav_fallback() {
        wp_page_menu(array(
            'show_home' => true,
            'menu_class' => 'nav top-nav', // adding custom nav class
            'include' => '',
            'exclude' => '',
            'echo' => true,
            'link_before' => '', // before each link
            'link_after' => ''                             // after each link
        ));
    }

    function dktm_side_nav() {
        // display the wp3 menu if available
        wp_nav_menu(array(
            'container' => false, // remove nav container
            'container_class' => 'menu clearfix', // class of container (should you choose to use it)
            'menu' => __('Side Menu', 'dktm'), // nav name
            'menu_class' => 'nav top-nav sidebar-nav', // adding custom nav class
            'theme_location' => 'side-menu', // where it's located in the theme
            'before' => '', // before the menu
            'after' => '', // after the menu
            'link_before' => '', // before each link
            'link_after' => '', // after each link
            'depth' => 0, // limit the depth of the nav
            'fallback_cb' => 'dktm_main_nav_fallback'      // fallback function
        ));
    }

    function dktm_footer_nav() {
        // display the wp3 menu if available
        wp_nav_menu(array(
            'container' => false, // remove nav container
            'container_class' => 'menu clearfix', // class of container (should you choose to use it)
            'menu' => __('Footer Menu', 'dktm'), // nav name
            'menu_class' => 'nav top-nav clearfix', // adding custom nav class
            'theme_location' => 'footer-menu', // where it's located in the theme
            'before' => '', // before the menu
            'after' => '', // after the menu
            'link_before' => '', // before each link
            'link_after' => '', // after each link
            'depth' => 0, // limit the depth of the nav
            'fallback_cb' => 'dktm_main_nav_fallback'      // fallback function
        ));
    }

    add_action('wp_ajax_nopriv_colorbox_popup', 'colorbox_popup_callback');
    add_action('wp_ajax_colorbox_popup', 'colorbox_popup_callback');

    function colorbox_popup_callback() {
        global $wpdb; // this is how you get access to the database
        global $wp_query;
        $post_type = $_GET['post_type'];
        $id = $_GET['id'];
        $temp = $wp_query;  // re-sets query
        if ($post_type == "page") {
            $args = array(
                'post_type' => array('page'),
                'page_id' => $id,
            );
        } else {
            $args = array(
                'p' => $id,
            );
        }
        $custom_query = new WP_Query($args);
        while ($custom_query->have_posts()) : $custom_query->the_post();
//            echo '<h2>';
//            the_title();
//            echo '</h2>';
            echo '<div class="colorbox_popup_wrapper">';
//            echo apply_filters('the_content', do_shortcode('[contact-form-7 id="49" title="Contact form 1"]'));
            the_content();
            echo '</div>';

        endwhile;
        $wp_query = $temp;  // re-sets query
        wp_reset_query();
        die(); // this is required to return a proper result
    }

    function template_chooser($template) {
        global $wp_query;
        $post_type = get_query_var('post_type');
        if ($wp_query->is_search && $post_type == 'information') {
            return locate_template('archive-information_search.php');  //  redirect to archive-search.php
        }
        return $template;
    }

    add_filter('template_include', 'template_chooser');

    function get_dktm_popup_edit($type = 'information', $title = "", $content = '') {
        global $pfs;
        //var_dump($pfs);
        if (is_object($pfs)) {
            if ($type == 'information') {
                $pfs->form('information', $title, $content);
                do_action('before');
            } else if ($type == 'post') {
                $pfs->form('post', $title, $content);
                do_action('before');
            } else if ($type == 'event') {
                $pfs->form('event', $title, $content);
                do_action('before');
            }
        }
    }

    function get_user_icon() {
        $user_id = get_current_user_id();
//        echo $user_id;
        $events = get_notified_event_list_by_user($user_id);
        $event_count_txt = '';
        $event_content = '';
//        debug($events);
        if (count($events) > 0) {
            $event_count_txt = '<span class="user_icon_number">' . count($events) . '</span>';
            $event_content .= '<div>';
            $event_content .= '<ul class="user_icon_content">';
            foreach ($events as $event) {
                $event_content .='<li>';
                $event_content .='<a class="fix_head_menu" href="' . $event->guid . '">';
                $event_content .=$event->post_title;
                $event_content .= tribe_events_event_schedule_details($event);
                $event_content .='</a>';
                $event_content .='</li>';
            }
            $event_content .= '</ul>';
            $event_content .= '</div>';
        }
        $output .='<a  href="javascript:void(0);" class="user_icon user_icon_trigger">User</a>' . $event_count_txt;
        $output .= $event_content;
        $notify = @$_GET['notify_me'];
        $msg = '';
        if ($notify == 1) {
            $msg = 'You have set a reminder to this event. This red notification will pop-up continuously for 7 days prior to the actual event. Please Note: Notifications will only be displayed if you are logged in DirectionKathmanu.com.';
        } else if ($notify == 2) {
            $msg = 'The reminder notification to this event has been removed.';
        } else if ($notify == 3) {
            $msg = 'Error occured. Please contact administrator.';
        }
        if ($msg != '') {
            $output .= '<div class="user_icon_notification"><div class="user_icon_triangle"></div><div class="user_icon_close"></div>';
            $output .= '<div class="user_icon_notification_content">' . $msg . '</div>';
            $output .= '</div>';
        }
        return $output;
    }

    function get_social_network_link($type) {
        global $dktmSetting;
        if ($type == "facebook") {
            $val = @$dktmSetting['facebook'];
        } else if ($type == "twitter") {
            $val = @$dktmSetting['twitter'];
        } else if ($type == "instagram") {
            $val = @$dktmSetting['instagram'];
        } else if ($type == "in") {
            $val = @$dktmSetting['linkedin'];
        } else if ($type == "you") {
            $val = @$dktmSetting['youtube'];
        } else {
            $val = '';
        }
        $output = '';
        if ($val != '') {
            $output .='<a  href="' . $val . '" target="_blank" class="' . $type . '">' . ucwords($type) . '</a>';
        }
        return $output;
    }

    /* notify me */

    function get_all_upcoming_event() {
        if (function_exists('tribe_get_events')) {
            $args = array(
                'eventDisplay' => 'upcoming',
                'posts_per_page' => -1,
            );
            $posts = tribe_get_events($args);
            return $posts;
        }
        return FALSE;
    }

    function get_notified_event_list_by_user($user_id) {
        $events = get_all_upcoming_event();
        $ret = array();
        if ($events && $user_id > 0) {
            $key = event_notification_key();
            $current_date = current_time('timestamp');
            $checking_date = date('Y-m-d H:i:s', strtotime('+7 days', $current_date));
            foreach ($events as $event) {
                //1. check if this user has set notify me?
                $post_id = $event->ID;
                $EventStartDate = $event->EventStartDate;
                $prev_users = get_post_meta($post_id, $key, true);
                $list = explode(',', $prev_users);
                if (in_array($user_id, $list)) {
                    //2. check if event is 7day before?
                    if ($checking_date >= $EventStartDate) {
                        $ret[] = $event;
                    }
                }
            }
        }
        return $ret;
    }

    function build_event_notification($user_id, $post_id) {
        $key = event_notification_key();
        $prev_users = get_post_meta($post_id, $key, true);
        $list = explode(',', $prev_users);
        $ret = array();
        if (count($list) > 0) {
            foreach ($list as $single) {
                if ($user_id != $single) {
                    $ret[] = $single;
                }
            }
            if (!in_array($user_id, $list)) {
                $ret[] = $user_id;
            }
        }
        return $ret;
    }

    function event_notification_key() {
        return '_dktmEventNotificationUsers';
    }

    function update_event_notification($post_id, $data) {
        $meta_key = event_notification_key();
        $csvData = '';
        if (is_array($data)) {
            $csvData = implode(',', $data);
        } else {
            $csvData = $data;
        }
        $ck = update_post_meta($post_id, $meta_key, $csvData);
        return $ck;
    }

    function check_event_notification($user_id, $post_id) {
        $key = event_notification_key();
        $prev_users = get_post_meta($post_id, $key, true);
        $list = explode(',', $prev_users);
        return (in_array($user_id, $list)) ? 1 : 0;
    }

    function get_current_url() {
        global $wp;
        $current_url = add_query_arg($wp->query_string, '', home_url($wp->request));
        return $current_url;
    }

    function get_event_notification($post_id, $title = "") {
        echo '<div class="tribe-events-event-cost" style="position: relative;">';
        $past_event = tribe_is_past();
        $show_status = 0; //-1:past event; 0: not logged in; 1: alredy notified; 2: not notified
        $user_id = 0;
        if (is_user_logged_in()) {
            global $current_user;
            get_currentuserinfo();
            $user_id = $current_user->ID;
            //check have already checked notify
            if (check_event_notification($user_id, $post_id)) {
                //already notified
                $show_status = 1;
            } else {
                $show_status = 2;
            }
        }
        $build_value = $user_id . "|" . $post_id;
        $unique_id = "dropdown-notify_me_" . $post_id;

        if ($past_event) {
            if ($show_status == 1) {
                $msg = "You've already received notification for the event.";
            } else {
                $msg = "This event has already past. You cannot get notification now.";
            }
            ?>
            <span class="btn btn_style1"  data-dropdown="#<?php echo $unique_id; ?>">
                Notify me<i class=" fa fa-caret-down paddingL10"></i>
            </span>
            <div id="<?php echo $unique_id; ?>" class="dropdown dropdown-tip fix_dropdown_position">
                <ul class="dropdown-menu-ui">
                    <li>
                        <label for="notify_me_<?php echo $post_id; ?>" class=""><?php echo $msg; ?></label>
                    </li>
                </ul>
            </div>
            <?php
        } else if ($show_status == 0) {//not logged in
            ?>
            <span  class="btn btn_style1" data-dropdown="#<?php echo $unique_id; ?>">
                Notify me<i class=" fa fa-caret-down paddingL10"></i>
            </span>
            <div id="<?php echo $unique_id; ?>" class="dropdown dropdown-tip fix_dropdown_position">
                <ul class="dropdown-menu-ui">
                    <li>
                        <label for="notify_me_<?php echo $post_id; ?>" class="">Please <a href="<?php echo wp_login_url(get_current_url()) ?>">login</a> or register to use this feature.</label>
                    </li>
                </ul>
            </div>
            <?php
        } else if ($show_status == 1 || $show_status == 2) {
//            $show_status = 1; //echo $show_status; //1. alredy notified; 2. not notified 
            ?>
            <span  class="btn btn_style1" data-dropdown="#<?php echo $unique_id; ?>">
                <?php if ($show_status == 1) { ?>
                    <img src="<?php echo get_template_directory_uri() . '/assets/jquery.notice/success.png'; ?>" alt="success" style="width: 18px; padding-right: 10px;" />
                <?php } ?>
                Notify me<i class=" fa fa-caret-down paddingL10"></i>
            </span>
            <div id="<?php echo $unique_id; ?>" class="dropdown dropdown-tip fix_dropdown_position">
                <ul class="dropdown-menu-ui">
                    <li>
                        <input <?php echo ($show_status == 1) ? 'checked="checked"' : ''; ?> type="checkbox" value="<?php echo $build_value; ?>" alt="<?php echo $title; ?>" id="notify_me_<?php echo $post_id; ?>"  class="event_notify_me event_notify_me_2 css-checkbox lrg"/> 
                        <label for="notify_me_<?php echo $post_id; ?>" class="css-label lrg vlad">Get Notification</label>
                    </li>
                </ul>
            </div>
            <?php
        }
        echo '</div>';
    }

    add_action('wp_ajax_nopriv_dktm_event_notification', 'dktm_event_notification_callback');
    add_action('wp_ajax_dktm_event_notification', 'dktm_event_notification_callback');

    function dktm_event_notification_callback() {
        $status = false;
        $user_id = $_GET['user_id'];
        $post_id = $_GET['post_id'];
        $is_notify = $_GET['is_notify'];
        $is_notify = ($is_notify == 1) ? 1 : 0;
        if (is_numeric($user_id) && $user_id > 0 && is_numeric($post_id) && $post_id > 0) {
            $data = build_event_notification($user_id, $post_id);
            $status = update_event_notification($post_id, $data);
        }
        $output['status'] = $status;
        $output['is_notify'] = $is_notify;
        $output['post_id'] = $post_id;
        die(json_encode($output)); // this is required to return a proper result
    }

    /* end notify me */



    add_action('init', 'custom_post_example');
    add_action('init', 'custom_post_register_taxonomy');

    function custom_post_register_taxonomy() {
        register_taxonomy(
                'entertainment_cat', 'entertainment', array(
            'hierarchical' => true,
            'label' => 'Entertainment Category',
            'query_var' => true,
            'rewrite' => array('slug' => 'entertainment-category')
                )
        );
    }

// let's create the function for the custom type
    function custom_post_example() {
        $labelentertainments = array(
            'name' => _x('entertainments', 'post type general name'),
            'singular_name' => _x('entertainment', 'post type singular name'),
            'add_new' => _x('Add New entertainment', 'dktm'),
            'add_new_item' => __('Add New entertainment'),
            'edit_item' => __('Edit entertainment'),
            'new_item' => __('New entertainment'),
            'all_items' => __('All entertainments'),
            'view_item' => __('View entertainment'),
            'search_items' => __('Search entertainments'),
            'not_found' => __('No entertainment found'),
            'not_found_in_trash' => __('No entertainment found in the Trash'),
            'parent_item_colon' => '',
            'menu_name' => 'Entertainments'
        );
        $argentertainments = array(
            'labels' => $labelentertainments,
            'description' => 'Holds dktm entertainments specific data',
            'public' => true,
            'menu_position' => 20,
            'supports' => array('title', 'editor', 'thumbnail', 'excerpt'), //, 'custom-fields'
            'has_archive' => true,
            'taxonomies' => array('entertainment_cat')
        );
        register_post_type('entertainment', $argentertainments);
    }

// Add to admin_init function
    add_filter('manage_edit-entertainment_columns', 'add_new_entertainment_columns');

    function add_new_entertainment_columns($entertainment_columns) {
        $new_columns['cb'] = '<input type="checkbox" />';
        //$new_columns['id'] = __('ID');
        $new_columns['title'] = 'Title';
        $new_columns['entertainment_cat'] = 'Entertainment Category';
        //$new_columns['images'] = __('Images');
        //$new_columns['author'] = __('Author');
        //$new_columns['tags'] = __('Tags');
        $new_columns['date'] = _x('Date', 'column name');
        return $new_columns;
    }

    add_action('manage_entertainment_posts_custom_column', 'my_manage_entertainment_columns', 10, 2);

    function my_manage_entertainment_columns($column, $post_id) {
        global $post;

        switch ($column) {

            //If displaying the 'genre' column. //
            case 'entertainment_cat' :

                // Get the genres for the post. //
                $terms = get_the_terms($post_id, 'entertainment_cat');

                //If terms were found.//
                if (!empty($terms)) {

                    $out = array();

                    //Loop through each term, linking to the 'edit posts' page for the specific term. //
                    foreach ($terms as $term) {
                        $out[] = sprintf('%s', esc_html(sanitize_term_field('name', $term->name, $term->term_id, 'entertainment_cat', 'display'))
                        );
//					$out[] = sprintf( '<a href="%s">%s</a>',
//						esc_url( add_query_arg( array( 'post_type' => $post->post_type, 'entertainment_cat' => $term->slug ), 'edit.php' ) ),
//						esc_html( sanitize_term_field( 'name', $term->name, $term->term_id, 'entertainment_cat', 'display' ) )
//					);
                    }

                    // Join the terms, separating them with a comma. //
                    echo join(', ', $out);
                }

                //If no terms were found, output a default message. //
                else {
                    _e('-');
                }

                break;

            // Just break out of the switch statement for everything else. //
            default :
                break;
        }
    }

    /* --------------------------------------------------FOR SORTING--------------------------
      // * ADMIN COLUMN - SORTING - MAKE HEADERS SORTABLE
      // * https://gist.github.com/906872

      add_filter("manage_edit-entertainment_sortable_columns", 'entertainment_sort');
      function entertainment_sort($columns) {
      $custom = array(
      'entertainment_cat' 	=> 'entertainment_cat',
      //'city' 		=> 'city'
      );
      return wp_parse_args($custom, $columns);

      }
      // Only run our customization on the 'edit.php' page in the admin.
      add_action( 'load-edit.php', 'my_edit_movie_load' );

      function my_edit_movie_load() {
      add_filter( 'request', 'my_sort_entertainment' );
      }

      // Sorts the movies.
      function my_sort_entertainment( $vars ) {

      //	Check if we're viewing the 'movie' post type.
      if ( isset( $vars['post_type'] ) && 'entertainment' == $vars['post_type'] ) {

      //		Check if 'orderby' is set to 'duration'.
      if ( isset( $vars['orderby'] ) && 'entertainment_cat' == $vars['orderby'] ) {

      //			 Merge the query vars with our custom variables.
      $vars = array_merge(
      $vars,
      array(
      'meta_key' => 'entertainment_cat',
      'orderby' => 'meta_value_num'
      )
      );
      }
      }

      return $vars;
      }


     */

    ///////////////login
    /////// information share login////////////
    function get_dktm_share_information_login() {
        echo '<h2>Please Login or Register to Post</h2>';
        get_dktm_login_form();
    }

    function get_dktm_login_form() {
        $current_url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
//                                        global $wp;
//                                        $current_url = add_query_arg( $wp->query_string, '', home_url( $wp->request ) );

        $args = array(
            'redirect' => $current_url,
            'form_id' => 'loginform-custom',
            'label_username' => __('Username'),
            'label_password' => __('Password'),
            'label_remember' => __('Remember Me'),
            'label_log_in' => __('Log In'),
            'remember' => true
        );
        echo '<div class="clearfix" style="width:100%">';
        wp_login_form($args);
        echo '</div>';
        wp_register("<div class='clear'></div><div class='registering'>", "<div class='clear'></div></div>");
        echo do_shortcode('[facebookall_login]');
    }

///////////////customize admin panel///////////////////////



    function bones_login_css() {
        wp_enqueue_style('bones_login_css', get_template_directory_uri() . '/css/login.css', false);
//        wp_enqueue_script('jquery-masonry',get_template_directory_uri() .'/js/jquery.masonry.min.js');
    }

// changing the logo link from wordpress.org to your site
    function bones_login_url() {
        return home_url();
    }

// changing the alt text on the logo to show your site name
    function bones_login_title() {
        return get_option('blogname');
    }

// calling it only on the login page
    add_action('login_enqueue_scripts', 'bones_login_css', 10);
    add_filter('login_headerurl', 'bones_login_url');
    add_filter('login_headertitle', 'bones_login_title');

    /* changes the "Register For This Site" text on the Wordpress login screen (wp-login.php) */

    function ik_change_login_message($message) {
        // change messages that contain 'Register' 
        if (strpos($message, 'Register') !== FALSE) {
            $newMessage = "Please provide the following details to register.";
            return '<p class="message register register_custom">' . $newMessage . '</p>';
        } else {
            return $message;
        }
    }

    add_action('login_message', 'ik_change_login_message');

    function excerpt($limit = 55) {
        $excerpt = explode(' ', get_the_excerpt(), $limit);
        if (count($excerpt) >= $limit) {
            array_pop($excerpt);
            $excerpt = implode(" ", $excerpt) . '...';
        } else {
            $excerpt = implode(" ", $excerpt);
        }
        $excerpt = preg_replace('`\[[^\]]*\]`', '', $excerpt);
        return $excerpt;
    }

    function content($limit = 55) {
        $content = explode(' ', get_the_content(), $limit);
        if (count($content) >= $limit) {
            array_pop($content);
            $content = implode(" ", $content) . '...';
        } else {
            $content = implode(" ", $content);
        }
        $content = preg_replace('/\[.+\]/', '', $content);
        $content = apply_filters('the_content', $content);
        $content = str_replace(']]>', ']]&gt;', $content);
        return $content;
    }

    function build_our_network_url() { //should be inside loop
        $ext_url = get_post_meta(get_the_ID(), 'wpcf-url', true);
        if (!isset($ext_url) || $ext_url == "") {
            $ext_url = get_site_url() . "/contact/";
        }
        return $ext_url;
    }

    function dktm_share() {
        if (shortcode_exists('really_simple_share')) {
            $ret = do_shortcode('[really_simple_share]');
            return $ret;
        }
//        if (function_exists('facebookall_get_socialshre')) {
//            return facebookall_get_socialshre();
//        }
        return false;
    }

    function dktm_comment() {
        if (function_exists('facebookall_get_fb_comments')) {
            return facebookall_get_fb_comments();
        }
        return false;
    }

    function get_thumbnail($size, $output = true, $exclude_content = false) { //should be inside loop
        //1. check featured image
        //2. check external url
        //3. get from content
        if (has_post_thumbnail()) {
            $img = get_the_post_thumbnail(get_the_ID(), $size);
//            the_post_thumbnail($size);
        } else {
            //get external url from post meta
            $url = esc_attr(get_post_meta(get_the_ID(), 'external_url', true));
            if ($url != "") {
                $title = get_the_title();
                $sizes = get_width_height_by_size($size);
                $style = "max-width:{$sizes['width']}px;";
                $img = "<img src='{$url}' title='{$title}' alt='{$title}' style='{$style}' />";
            } else {

                if (!$exclude_content) {
                    $first_image = catch_first_image();
                    if ($first_image != "") {
                        $title = get_the_title();
                        $sizes = get_width_height_by_size($size);
                        $style = "max-width:{$sizes['width']}px;";
                        $img = "<img src='{$first_image}' title='{$title}' alt='{$title}' style='{$style}' />";
                    }
                }
            }
        }
        if ($img != "") {
            if ($output) {
                echo $img;
            } else {
                return $img;
            }
        }
        else
            return false;
    }

    function catch_first_image() {
        global $post, $posts;
        $first_img = '';
        ob_start();
        ob_end_clean();
        $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
        $first_img = $matches [1] [0];
        if (empty($first_img)) { //Defines a default image
            $output = preg_match_all('/<img.+src.+=.+[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
            $first_img = $matches [1] [0];
            if (empty($first_img)) {
                $first_img = false; //"/images/default.jpg";
            }
        }
        return $first_img;
    }

    function get_width_height_by_size($size) {
        global $_wp_additional_image_sizes;
        foreach (get_intermediate_image_sizes() as $s) {
            if ($s == $size) {
                if (isset($_wp_additional_image_sizes[$s])) {
                    $width = intval($_wp_additional_image_sizes[$s]['width']);
                    $height = intval($_wp_additional_image_sizes[$s]['height']);
                } else {
                    $width = get_option($s . '_size_w');
                    $height = get_option($s . '_size_h');
                }
                return array('width' => $width, 'height' => $height);
            }
        }
    }

    add_action('wp_ajax_nopriv_masonry_paging', 'masonry_paging_callback');
    add_action('wp_ajax_masonry_paging', 'masonry_paging_callback');

    function masonry_paging_callback() {
        $template = $_GET['template'];
        if (file_exists(TEMPLATEPATH . "/templates/{$template}.php")) {
            include TEMPLATEPATH . "/templates/{$template}.php";
        }
        die();
    }

    /* event */

    function get_event_venue_list_option($selected_id = '') {
        $my_venue_ids = array();
        $my_venues = get_event_venue_list();
        $my_venue_options = '';
        if (!empty($my_venues)) {
            foreach ($my_venues as $my_venue) {
                $my_venue_ids[] = $my_venue->ID;
                $venue_title = wp_kses(get_the_title($my_venue->ID), array());
                $selected = ($selected_id == $my_venue->ID) ? 'selected="selected"' : '';

                $my_venue_options .= '<option value="' . esc_attr($my_venue->ID) . '"';
                $my_venue_options .= $selected;
                $my_venue_options .= '>' . $venue_title . '</option>';
            }
        }
        return $my_venue_options;
    }

    function get_event_venue_list() {
        $defaults = array(
            'post_type' => TribeEvents::VENUE_POST_TYPE,
            'nopaging' => 1,
            'post_status' => 'publish',
            'ignore_sticky_posts ' => 1,
            'orderby' => 'title',
            'order' => 'ASC',
            'p' => null
        );
        $current_user = wp_get_current_user();
        if (0 != $current_user->ID) {
            $args = array('post_status' => array('publish', 'draft', 'private'));
            $args = wp_parse_args($args, $defaults);
            $r = new WP_Query($args);
            if ($r->have_posts()) :
                return $r->posts;
            endif;
            wp_reset_query();
        }
        return false;
    }

    function get_event_organizer_list_option($selected_id = '') {
        $my_venue_ids = array();
        $my_venues = get_event_organizer_list();
        $my_venue_options = '';
        if (!empty($my_venues)) {
            foreach ($my_venues as $my_venue) {
                $my_venue_ids[] = $my_venue->ID;
                $venue_title = wp_kses(get_the_title($my_venue->ID), array());
                $selected = ($selected_id == $my_venue->ID) ? 'selected="selected"' : '';

                $my_venue_options .= '<option value="' . esc_attr($my_venue->ID) . '"';
                $my_venue_options .= $selected;
                $my_venue_options .= '>' . $venue_title . '</option>';
            }
        }
        return $my_venue_options;
    }

    function get_event_organizer_list() {
        $defaults = array(
            'post_type' => TribeEvents::ORGANIZER_POST_TYPE,
            'nopaging' => 1,
            'post_status' => 'publish',
            'ignore_sticky_posts ' => 1,
            'orderby' => 'title',
            'order' => 'ASC',
            'p' => null
        );
        $current_user = wp_get_current_user();
        if (0 != $current_user->ID) {
            $args = array('post_status' => array('publish', 'draft', 'private'));
            $args = wp_parse_args($args, $defaults);
            $r = new WP_Query($args);
            if ($r->have_posts()) :
                return $r->posts;
            endif;
            wp_reset_query();
        }
        return false;
    }

    function check_dktm_user($ck_is_admin_page = true) {
        if ($ck_is_admin_page) {
            $is_admin_page = is_admin();
        } else {
            $is_admin_page = true;
        }
        global $current_user;
        get_currentuserinfo();
        $ck_dktm_user = (user_can($current_user, "subscriber"));
        return ($is_admin_page && $ck_dktm_user) ? true : false;
    }

    function expound_scripts1() {
        // Don't forget to bump the version numbers in style.css and editor-style.css
        wp_enqueue_script('jquery');
        wp_enqueue_script('jquery-ui-core');
        wp_enqueue_script('jquery-ui-datepicker');
//        wp_enqueue_script('jquery-ui-accordion');
//        wp_enqueue_script('bootstrap-select-js', get_stylesheet_directory_uri() . "/assets/bootstrap-select/bootstrap-select.js", array('jquery'));
//        wp_enqueue_script('bootstrap-js', get_stylesheet_directory_uri() . "/assets/bootstrap-select/bootstrap.min.js", array('jquery'));
//        wp_enqueue_script('bspq-main-js', get_stylesheet_directory_uri() . "/assets/main.js", array('jquery', 'jquery-ui-autocomplete'), false, false);
//        $jsConstant = array(
//            'ajaxurl' => admin_url('admin-ajax.php'),
//        );
//        wp_localize_script('bspq-main-js', 'jsConstant', $jsConstant);
    }

    add_action('wp_footer', 'expound_scripts1');

    
    function dktm_event_share($attr=array()){
        include get_stylesheet_directory().'/templates/event-add_to_calendar.php';
    }
    
    $files = array(
        get_stylesheet_directory() . '/helpers/shortcode.php',
        get_stylesheet_directory() . '/helpers/admin_custom.php'
    );
    foreach ($files as $file) {
        if (file_exists($file)) {
            include $file;
        }
    }